{extend name='comm/base' /}

{block name='header'}
{include file='comm/header'}
{/block}

{block name='slider'}
{include file='comm/slider'}
{/block}

{block name='main'}
<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">会员管理</a>
                </li>
                <li class="active">角色管理</li>
            </ul><!-- /.breadcrumb -->
        </div>
        <div class="page-content">

            <div class="page-header">
                <h1>
                    角色
                    <small>
                        <i class="ace-icon fa fa-angle-double-right"></i>
                        新增角色
                    </small>
                </h1>
            </div><!-- /.page-header -->
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="group_name" >角色名称</label>
                            <div class="col-sm-9">
                                <input type="text" id="group_name" placeholder="角色名称" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>


                        <div class="space-4"></div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right">角色状态</label>
                            <div class="col-sm-3">
                                <select class="chosen-select form-control" id="status" data-placeholder="Choose a State...">
                                    <option value="0">否</option>
                                    <option value="1">是 </option>
                                </select>
                            </div>
                        </div>

                        <div class="space-4"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="remark">描述</label>
                            <div class="col-sm-9">
                                <input type="text" id="remark" placeholder="描述" class="col-xs-10 col-sm-5" />
                            </div>
                        </div>
                        <div class="space-4"></div>
                        <div class="space-4"></div>

                        <!--<div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="remark">权限分配</label>
                            <div class="col-sm-9">
                            {volist name="menuData" id="vo"}

                            <input type="checkbox"   value="{$vo.id}">{$vo.name}<br>

                            {/volist}
                            </div>
                        </div>-->


                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="remark">
                                权限选择 </label>
                            <div class="col-sm-9">
                                <div class="col-sm-10">
                                    {volist name="menuData" id="v"}
                                    {if $v['parent_id']==null}
                                        <div class="row">
                                            <div class="widget-box">

                                                <div class="widget-header">
                                                    {if $v['parent_id']==null}
                                                    <h4 class="widget-title">
                                                        <label>
                                                            <input name="rules[]"
                                                                   class="ace ace-checkbox-2 father"
                                                            type="checkbox" value="{$v['id']}"/>
                                                            <span class="lbl"> {$v['name']}</span>
                                                        </label>
                                                    </h4>
                                                    {/if}
                                                    <div class="widget-toolbar">
                                                        {notempty name="v.children"}
                                                            <a href="#" data-action="collapse">
                                                                <i class="ace-icon fa fa-chevron-up"></i>
                                                            </a>
                                                        {/notempty}
                                                    </div>
                                                </div>

                                                {notempty name="v.children"}
                                                    <div class="widget-body">
                                                        <div class="widget-main row">
                                                            {volist name="v.children" id="vv"}
                                                                <label class="col-xs-2" style="width:160px;">
                                                                    <input  name="rules[]"
                                                                           class="ace ace-checkbox-2 children"
                                                                    type="checkbox" value="{$vv['id']}"/>
                                                                    <span class="lbl"> {$vv['name']}</span>
                                                                </label>
                                                                {volist name="vv.children" id="vvv"}
                                                                    <label class="col-xs-2"
                                                                           style="width:160px;">
                                                                        <input name="rules[]"
                                                                               class="ace ace-checkbox-2 children"
                                                                        type="checkbox" value="{$vvv['id']}"/>
                                                                        <span class="lbl"> {$vvv['name']}</span>
                                                                    </label>
                                                                {/volist}
                                                            {/volist}
                                                        </div>
                                                    </div>
                                                {/notempty}
                                            </div>
                                        </div>
                                    {/if}
                                    {/volist}
                                </div>
                            </div>
                        </div>


                        <div class="clearfix form-actions">
                            <div class="col-md-offset-3 col-md-9">
                                <button class="btn btn-primary" type="button" id="save_btn">
                                    保存
                                </button>
                            </div>
                        </div>

                        <div class="hr hr-24"></div>
                    </form>

                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->
{/block}

{block name='footer'}
{include file='comm/footer'}
{/block}
{block name='script'}

<script src="__ace_js__/jquery-2.1.4.min.js"></script>

<!-- <![endif]-->
<!--[if IE]>
<script src="__ace_js__/jquery-1.11.3.min.js"></script>
<![endif]-->
<script type="text/javascript">
    if('ontouchstart' in document.documentElement) document.write("<script src='__ace_js__/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="__ace_js__/bootstrap.min.js"></script>

<!-- ace scripts -->
<script src="__ace_js__/ace-elements.min.js"></script>
<script src="__ace_js__/ace.min.js"></script>
<script src="__ace_js__/chosen.jquery.min.js"></script>
<script lang="javascript">

    $(".children").click(function () {
        $(this).parent().parent().parent().parent().find(".father").prop("checked", true);
    })
    $(".father").click(function () {
        if (this.checked) {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", true);
        } else {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", false);
        }
    })

$('#save_btn').click(function(){
    var group_name = $('#group_name').val();
    var status = $('#status').val();
    var remark = $('#remark').val();
    var menu_auth=[];
    $("input[type='checkbox']:checked").each(function(i){
        menu_auth[i] = $(this).val();
    });



    if(group_name == ''){
      swal({
          type: 'warning', // 弹框类型
          title: '请输入角色名称', //标题
          confirmButtonColor: '#438EB9',// 确定按钮的 颜色
          confirmButtonText: '确定',// 确定按钮的 文字
      });
      return false;
    }
    $.ajax({
        url:"{:url('admin.auth_group.add')}",
        type:'POST',
        dataType:'JSON',
        data:{'group_name':group_name,'menu_auth':menu_auth,'status':status,'remark':remark},
        success:function(res){
            if(res.code == 1){
                swal({
                    type: 'success', // 弹框类型
                    title: '操作成功', //标题
                    confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                    confirmButtonText: '确定',// 确定按钮的 文字
                }).then((isConfirm) => {
                    //判断 是否 点击的 确定按钮
                    if (isConfirm.value) {
                        location.href = "{:url('admin.auth_group.index')}";
                    }
                });
            }else{
                swal({
                    type: 'warning', // 弹框类型
                    title:res.msg, //标题
                    confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                    confirmButtonText: '确定',// 确定按钮的 文字
                });
            }
            return false;
        },error:function(e){
            swal({
                type: 'error', // 弹框类型
                title:e.msg, //标题
                confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                confirmButtonText: '确定',// 确定按钮的 文字
            });
        }
    })
})


</script>
{/block}






